package cn.com.infohold.smartcity.utils;

import android.app.Activity;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;

/**
 * Created by zhangyahui on 2017/5/3.
 */

public class CommonUtils {
    public static int px2sp(Context context, float pxValue) {
        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
        return (int) (pxValue / fontScale + 0.5f);
    }
    public static int dp2px(Context context,float dipValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }
    /**
     * 强制隐藏输入法键盘
     */
    public static void hideSoftInput(Context context) {
        if (((Activity) context).getCurrentFocus() != null) {
            ((InputMethodManager) context.getSystemService(((Activity) context).INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(((Activity) context).getCurrentFocus()
                                    .getWindowToken(),
                            InputMethodManager.HIDE_NOT_ALWAYS);
        }

    }
}
